﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using OgilvyOne.Ext.Weibo.Common;
using OgilvyOne.Ext.Weibo.Lib;
using OgilvyOne.Ext.Weibo.Model;

namespace OgilvyOne.Ext.Weibo.Lib.Test
{
    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class MicroBlogTest
    {
        public MicroBlogTest()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，该上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        //
        // 编写测试时，可以使用以下附加特性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前，使用 TestInitialize 来运行代码
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在每个测试运行完之后，使用 TestCleanup 来运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestGetMyInterestedUserIDs()
        {
            string token = "2.00kYAxbCwUCZUB017675bd3dVpRlIC";
            OAuthAccessToken accessToken = new OAuthAccessToken();
            accessToken.Token = token;
            accessToken.UserID = "2393053602";

            Collection<InterestedUserInfo> users = Microblog.GetMayInterestedUserIDs(accessToken, 200, null);
            Assert.AreNotEqual(0, users.Count);
        }

        [TestMethod]
        public void TestGetMyInterestedUsers()
        {
            string token = "2.00kYAxbCwUCZUB017675bd3dVpRlIC";
            OAuthAccessToken accessToken = new OAuthAccessToken();
            accessToken.Token = token;
            accessToken.UserID = "2393053602";

            Collection<UserInfo> users = Microblog.GetMayInterestedUsers(accessToken, 200, null);
            Assert.AreNotEqual(0, users.Count);
        }

        [TestMethod]
        public void TestPostStatusWithPic()
        {
            try
            {
                string token = "2.00kYAxbCwUCZUBd2c341d76201lH6P";
                OAuthAccessToken accessToken = new OAuthAccessToken();
                accessToken.Token = token;
                accessToken.UserID = "2393053602";

                string imgPath = @"E:\8ea319a2gw1dopbrtwkhzj.jpg";

                UpdateStatusWithPicInfo info = new UpdateStatusWithPicInfo();
                info.Pic = imgPath;
                info.Status = "馨儿";

                StatusInfo status = Microblog.PostStatusWithPic(accessToken, info);
                string s = status.MiddlePic;
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
        }

        [TestMethod]
        public void TestConvert()
        {
            string filePath = @"C:\Users\victor.liu\Desktop\json.txt";
            string json = File.ReadAllText(filePath);
            UserInfo[] users = JsonSerializationHelper.JsonToObject<UserInfo[]>(json);
            Assert.AreNotEqual(null, users);
            Assert.AreNotEqual(0, users.Length);
        }
    }
}
